#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

# In some cases, while booting a virtual machine, an IDE controller
# will be created for it. It seems that the VirtualBox GUI likes doing
# this: when a particular machine has booted at least once with its
# GUI turned on, this will happen pretty consistently.
#
# Having an IDE controller and a SATA controller breaks the assumptions
# in the systemvm scripts about what disks are attached, causing it to
# not find the systemvm.iso.
#
# So, we delete the IDE controller using Vagrant.
#
# Unfortunately, when the IDE controller does not exist, that deletion
# fails, causing vagrant to fail. To work around this, we inject this
# script into the path, causing vagrant to try to continue booting.

/usr/bin/VBoxManage "$@"
exitcode=$?

if [[ "$1" == "storagectl" ]]; then
  exit 0
else
  exit ${exitcode}
fi
